package org.tote.command;

import java.util.Map;

import org.tote.controller.BaseController;

/**
 * This command enable to pass information between controller and service, ...
 * 
 */
public class ControllerCommand {
	public static final String SUCCESS = "<strong>Well done!</strong>";
	public static final String ERROR = "<strong>Error!</strong>";
	public static final String WARNING = "<strong>Warning!</strong>";

	private String warningMessage;
	private String warningForm;
	private String errorMessage;
	private String errorForm;
	private String successMessage;

	public String getWarningMessage() {
		return warningMessage;
	}

	public void setWarningMessage(String warningMessage) {
		this.warningMessage = warningMessage;
	}

	public void addWarningMessage(String message) {
		if (this.warningMessage == null)
			this.warningMessage = message;
		else
			this.warningMessage += message;
	}

	public String getWarningForm() {
		return warningForm;
	}

	public void setWarningForm(String warningForm) {
		this.warningForm = warningForm;
	}

	public void addWarningForm(String message) {
		if (this.warningForm == null)
			this.warningForm = message;
		else
			this.warningForm += message;
	}

	public String getErrorMessage() {
		return errorMessage;
	}

	public void setErrorMessage(String errorMessage) {
		this.errorMessage = errorMessage;
	}

	public void addErrorMessage(String message) {
		if (this.errorMessage == null)
			this.errorMessage = message;
		else
			this.errorMessage += message;
	}

	public String getErrorForm() {
		return errorForm;
	}

	public void setErrorForm(String errorForm) {
		this.errorForm = errorForm;
	}

	public void addErrorForm(String message) {
		if (this.errorForm == null)
			this.errorForm = message;
		else
			this.errorForm += message;
	}

	public String getSuccessMessage() {
		return successMessage;
	}

	public void setSuccessMessage(String successMessage) {
		this.successMessage = successMessage;
	}

	public void addSuccessMessage(String message) {
		if (this.successMessage == null)
			this.successMessage = message;
		else
			this.successMessage += message;
	}

	public void putToModel(Map<String, Object> model) {
		if (warningMessage != null)
			model.put(BaseController.ALERT_WARNING_MESSAGE, warningMessage);
		if (warningForm != null)
			model.put(BaseController.ALERT_WARNING_FORM, warningForm);
		if (errorMessage != null)
			model.put(BaseController.ALERT_ERROR_MESSAGE, errorMessage);
		if (errorForm != null)
			model.put(BaseController.ALERT_ERROR_FORM, errorForm);
		if (successMessage != null)
			model.put(BaseController.ALERT_SUCCESS_MESSAGE, successMessage);
	}

	public void clean() {
		warningMessage = null;
		warningForm = null;
		errorMessage = null;
		errorForm = null;
		successMessage = null;
	}
}
